home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / srumbler.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  5KB  |  185 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10.  
  11. extern unsigned char *spriteram;
  12. extern size_t spriteram_size;
  13.  
  14. unsigned char *srumbler_backgroundram,*srumbler_foregroundram;
  15. static struct tilemap *bg_tilemap,*fg_tilemap;
  16. static int flipscreen;
  17.  
  18.  
  19.  
  20. /***************************************************************************
  21.  
  22.   Callbacks for the TileMap code
  23.  
  24. ***************************************************************************/
  25.  
  26. static void get_fg_tile_info(int tile_index)
  27. {
  28.     unsigned char attr = srumbler_foregroundram[2*tile_index];
  29.     SET_TILE_INFO(0,srumbler_foregroundram[2*tile_index + 1] + ((attr & 0x03) << 8),(attr & 0x3c) >> 2)
  30.     tile_info.flags = (attr & 0x40) ? TILE_IGNORE_TRANSPARENCY : 0;
  31. }
  32.  
  33. static void get_bg_tile_info(int tile_index)
  34. {
  35.     unsigned char attr = srumbler_backgroundram[2*tile_index];
  36.     SET_TILE_INFO(1,srumbler_backgroundram[2*tile_index + 1] + ((attr & 0x07) << 8),(attr & 0xe0) >> 5)
  37.     tile_info.flags = TILE_SPLIT((attr & 0x10) >> 4);
  38.     if (attr & 0x08) tile_info.flags |= TILE_FLIPY;
  39. }
  40.  
  41.  
  42.  
  43. /***************************************************************************
  44.  
  45.   Start the video hardware emulation.
  46.  
  47. ***************************************************************************/
  48.  
  49. int srumbler_vh_start(void)
  50. {
  51.     fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,8,8,64,32);
  52.     bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_SPLIT,    16,16,64,64);
  53.  
  54.     if (!fg_tilemap || !bg_tilemap)
  55.         return 1;
  56.  
  57.     fg_tilemap->transparent_pen = 3;
  58.  
  59.     bg_tilemap->transmask[0] = 0xffff; /* split type 0 is totally transparent in front half */
  60.     bg_tilemap->transmask[1] = 0x07ff; /* split type 1 has pens 0-10 transparent in front half */
  61.  
  62.     return 0;
  63. }
  64.  
  65.  
  66.  
  67. /***************************************************************************
  68.  
  69.   Memory handlers
  70.  
  71. ***************************************************************************/
  72.  
  73. WRITE_HANDLER( srumbler_foreground_w )
  74. {
  75.     if (srumbler_foregroundram[offset] != data)
  76.     {
  77.         srumbler_foregroundram[offset] = data;
  78.         tilemap_mark_tile_dirty(fg_tilemap,offset/2);
  79.     }
  80. }
  81.  
  82. WRITE_HANDLER( srumbler_background_w )
  83. {
  84.     if (srumbler_backgroundram[offset] != data)
  85.     {
  86.         srumbler_backgroundram[offset] = data;
  87.         tilemap_mark_tile_dirty(bg_tilemap,offset/2);
  88.     }
  89. }
  90.  
  91.  
  92. WRITE_HANDLER( srumbler_4009_w )
  93. {
  94.     /* bit 0 flips screen */
  95.     flipscreen = data & 1;
  96.     tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
  97.  
  98.     /* bits 4-5 used during attract mode, unknown */
  99.  
  100.     /* bits 6-7 coin counters */
  101.     coin_counter_w(0,data & 0x40);
  102.     coin_counter_w(1,data & 0x80);
  103. }
  104.  
  105.  
  106. WRITE_HANDLER( srumbler_scroll_w )
  107. {
  108.     static int scroll[4];
  109.  
  110.     scroll[offset] = data;
  111.  
  112.     tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
  113.     tilemap_set_scrolly(bg_tilemap,0,scroll[2] | (scroll[3] << 8));
  114. }
  115.  
  116.  
  117.  
  118. /***************************************************************************
  119.  
  120.   Display refresh
  121.  
  122. ***************************************************************************/
  123.  
  124. static void draw_sprites(struct osd_bitmap *bitmap)
  125. {
  126.     int offs;
  127.  
  128.     /* Draw the sprites. */
  129.     for (offs = spriteram_size-4; offs>=0;offs -= 4)
  130.     {
  131.         /* SPRITES
  132.         =====
  133.         Attribute
  134.         0x80 Code MSB
  135.         0x40 Code MSB
  136.         0x20 Code MSB
  137.         0x10 Colour
  138.         0x08 Colour
  139.         0x04 Colour
  140.         0x02 y Flip
  141.         0x01 X MSB
  142.         */
  143.  
  144.  
  145.         int code,colour,sx,sy,flipy;
  146.         int attr=spriteram[offs+1];
  147.         code = spriteram[offs];
  148.         code += ( (attr&0xe0) << 3 );
  149.         colour = (attr & 0x1c)>>2;
  150.         sy = spriteram[offs + 2];
  151.         sx = spriteram[offs + 3] + 0x100 * ( attr & 0x01);
  152.         flipy = attr & 0x02;
  153.  
  154.         if (flipscreen)
  155.         {
  156.             sx = 496 - sx;
  157.             sy = 240 - sy;
  158.             flipy = !flipy;
  159.         }
  160.  
  161.         drawgfx(bitmap,Machine->gfx[2],
  162.                 code,
  163.                 colour,
  164.                 flipscreen,flipy,
  165.                 sx, sy,
  166.                 &Machine->drv->visible_area,TRANSPARENCY_PEN,15);
  167.     }
  168. }
  169.  
  170.  
  171. void srumbler_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  172. {
  173.     tilemap_update(ALL_TILEMAPS);
  174.  
  175.     if (palette_recalc())
  176.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  177.  
  178.     tilemap_render(ALL_TILEMAPS);
  179.  
  180.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_BACK);
  181.     draw_sprites(bitmap);
  182.     tilemap_draw(bitmap,bg_tilemap,TILEMAP_FRONT);
  183.     tilemap_draw(bitmap,fg_tilemap,0);
  184. }
  185.